class AuthorProvider {
    constructor(){
        this.authMap = {};
        this.app();
    }
    init(auths) {
        if(Array.isArray(auths)){
            this.authMap = auths.reduce((p, n) => { p[n.code] = n; return p; }, {});
        }
    }
    app(){
        if(Object.keys(this.authMap).length === 0){
            const user = JSON.parse(window.localStorage.getItem('user')) || {};
            this.init(user.roleMenuList || []);
        }
    }
    has(code) {
        return !Array.isArray(code) ? !!this.authMap[code] : code.some(c => !!this.authMap[c]);
    }
}

export const authProvider = new AuthorProvider();